package struts.xml;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

public class XMLFactory {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(XMLFactory.class);

	public static Map<String, String> readXml(String path) {

		Map<String, String> map = new HashMap<String, String>();
		logger.info("********初始化xml*****");
		SAXBuilder builder = new SAXBuilder();
		try {
			Document documet = builder.build(new File(path));
			Element root = documet.getRootElement();
			Element context = root.getChild("context");
			
			if(context!=null){
				map.put("base-package", context.getAttributeValue("base-package"));
			}
			

		} catch (Exception e) {
			logger.error("readXml(String)", e);
		}
		return map;
	}

	public static void main(String[] args) {

		readXml("e:/struts-config.xml");
	}
}
